import 'package:cloud_medicine/components/tag.dart';
import 'package:cloud_medicine/components/user_avatar.dart';
import 'package:flutter/material.dart';

class MessageUserShow extends StatelessWidget {
  final String avatar;
  final String realname;
  final int userID;
  final String createTime;
  final String abstract;
  final int receive;

  MessageUserShow({
    Key key,
    @required this.avatar,
    @required this.realname,
    @required this.userID,
    @required this.createTime,
    @required this.abstract,
    this.receive,
  }) : super(key: key);

  showTags() {
    if (receive == null) {
      return Container();
    }

    Map<int, String> contrastText = {
      0: '未应答',
      1: '已同意',
      -1: '已拒绝',
    };

    Map<int, Color> contrastColor = {
      0: Colors.yellow,
      1: Colors.green,
      -1: Colors.red,
    };

    return Row(
      children: <Widget>[
        SizedBox(width: 5),
        Tag(
          text: contrastText[receive],
          bgColor: contrastColor[receive],
          fontSize: 10,
        )
      ],
    );
  }

  @override
  Widget build(BuildContext context) {
    return Row(
      children: <Widget>[
        UserAvatar(
          avatar: avatar,
          imageStyle: 60,
          userID: userID,
        ),
        SizedBox(width: 5),
        Expanded(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.spaceAround,
            crossAxisAlignment: CrossAxisAlignment.start,
            children: <Widget>[
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: <Widget>[
                  Row(
                    children: <Widget>[
                      Text(
                        realname,
                        style: TextStyle(fontSize: 18),
                      ),
                      showTags()
                    ],
                  ),
                  Text(
                    createTime,
                    style: TextStyle(color: Colors.grey),
                  )
                ],
              ),
              Text(
                abstract,
                maxLines: 1,
                overflow: TextOverflow.ellipsis,
                style: TextStyle(color: Colors.grey),
              )
            ],
          ),
        )
      ],
    );
  }
}
